package com.fjwt.gz.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjwt.gz.db.dto.FansActivityDTO;
import com.fjwt.gz.db.entity.FansActivityEntity;
import com.fjwt.gz.db.vo.ActivityListVO;
import com.fjwt.gz.db.vo.FansActivityVO;
import com.fjwt.gz.service.mapper.FansActivityMapper;
import com.fjwt.gz.util.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 会员浏览/参与活动记录表 服务实现类
 * </p>
 *
 * @author shiyonghao
 * @since 2025-04-09
 */
@Slf4j
@Service
public class FansActivityService extends ServiceImpl<FansActivityMapper, FansActivityEntity> {

    @Autowired
    private FansActivityMapper fansActivityMapper;

    /**
     * 增加活动记录
     *
     * @param fansActivityDTO
     */
    public void addFansActivityEntity(FansActivityDTO fansActivityDTO) {
        FansActivityEntity fansActivityEntity = new FansActivityEntity();
        fansActivityEntity.setActivityId(fansActivityDTO.getActivityId());
        fansActivityEntity.setFansId(fansActivityDTO.getFansId());
        fansActivityEntity.setAppId(fansActivityDTO.getAppId());
//        fansActivityEntity.setShareRecordId(fansActivityDTO.getShareRecordId());
        if (0 == fansActivityDTO.getJoinType()) {
            fansActivityEntity.setJoinType(fansActivityDTO.getJoinType());
        } else if (1 == fansActivityDTO.getJoinType()) {
            fansActivityEntity.setJoinType(fansActivityDTO.getJoinType());
            fansActivityEntity.setInviterId(fansActivityDTO.getShareFansId());
        } else if (2 == fansActivityDTO.getJoinType()) {
            fansActivityEntity.setJoinType(fansActivityDTO.getJoinType());
            fansActivityEntity.setInviterId(fansActivityDTO.getActivityChannelId());
        } else if (3 == fansActivityDTO.getJoinType()) {
            fansActivityEntity.setJoinType(fansActivityDTO.getJoinType());
        } else if (4 == fansActivityDTO.getJoinType()) {
            fansActivityEntity.setJoinType(fansActivityDTO.getJoinType());
            fansActivityEntity.setInviterId(fansActivityDTO.getQrcodeRecordId());
        } else if (5 == fansActivityDTO.getJoinType()) {
            fansActivityEntity.setJoinType(fansActivityDTO.getJoinType());
            fansActivityEntity.setInviterId(fansActivityDTO.getFansId());
        } else if (6 == fansActivityDTO.getJoinType()) {
            fansActivityEntity.setJoinType(fansActivityDTO.getJoinType());
            fansActivityEntity.setInviterId(fansActivityDTO.getFansId());
        }
        log.info("增加活动记录,参数：{}", JsonUtils.toJson(fansActivityEntity));
        save(fansActivityEntity);
    }

    public IPage<ActivityListVO> getFansActivityList(IPage<?> page, Long fansId, String appId) {
        return fansActivityMapper.getFansActivityList(page, fansId, appId);
    }
    public FansActivityVO getFansActivityDetail(Long activityId) {
        return fansActivityMapper.getFansActivityDetail(activityId);
    }

    /**
     * 增加参与活动记录
     */
    public void addRecord(Long fansId,String appId,Long activityId,Integer shareRecordId){
        FansActivityEntity fansActivityEntity=new FansActivityEntity();
        fansActivityEntity.setActivityId(activityId);
        fansActivityEntity.setFansId(fansId);
        fansActivityEntity.setAppId(appId);
        fansActivityEntity.setCreatedAt(new Date());
        fansActivityEntity.setShareRecordId(shareRecordId);
        save(fansActivityEntity);
    }

}
